const util= require('../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: '',
    serverTotal: '',
    serverList: [],
    serverDate: ''
  },
  jumpHome: function () {
    wx.redirectTo({
      url: '../home/home',
    })
  },
  jumpWarn: function () {
    wx.redirectTo({
      url: '../warn/warn',
    })
  },
  jumpCamera: function () {
    wx.redirectTo({
      url: '../camera/camera',
    })
  },
  jumpServer: function () {
    wx.redirectTo({
      url: 'server',
    })
  },
  serverManager: function () {
    wx.navigateTo({
      url: '/pages/serverManage/serveManage',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        that.setData({
          token: res.data
        })

        let header = {
          'context-type': 'application/json',
          'UserToken': that.data.token,
          'Cookie': wx.getStorageSync("sessionid")
        }
        wx.request({
          url: 'https://www.2edge.cn/rest/userDevices/queryList',
          method: 'post',
          header: header,
          data: {
            "pageNum": '',
            "pageSise": '',
            "conditions": []
          },
          success: function (res) {
            // console.log(res.data.data.records);
            that.setData({
              serverTotal: res.data.data.total,
              serverList: res.data.data.records,
              serverDate: util.formatTime(new Date())
            })
            
          }
        })
      }
    })
  }
})